<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Class template rbtree_best_fit</title>
<link rel="stylesheet" href="../../../../doc/src/boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="../../index.html" title="The Boost C++ Libraries BoostBook Documentation Subset">
<link rel="up" href="../../interprocess/indexes_reference.html#header.boost.interprocess.mem_algo.rbtree_best_fit_hpp" title="Header &lt;boost/interprocess/mem_algo/rbtree_best_fit.hpp&gt;">
<link rel="prev" href="mapped_region/advice_types.html" title="Type advice_types">
<link rel="next" href="simple_seq_fit.html" title="Class template simple_seq_fit">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr>
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../boost.png"></td>
<td align="center"><a href="../../../../index.html">Home</a></td>
<td align="center"><a href="../../../../libs/libraries.htm">Libraries</a></td>
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
<td align="center"><a href="../../../../more/index.htm">More</a></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="mapped_region/advice_types.html"><img src="../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../../interprocess/indexes_reference.html#header.boost.interprocess.mem_algo.rbtree_best_fit_hpp"><img src="../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="simple_seq_fit.html"><img src="../../../../doc/src/images/next.png" alt="Next"></a>
</div>
<div class="refentry">
<a name="boost.interprocess.rbtree_best_fit"></a><div class="titlepage"></div>
<div class="refnamediv">
<h2><span class="refentrytitle">Class template rbtree_best_fit</span></h2>
<p>boost::interprocess::rbtree_best_fit</p>
</div>
<h2 class="refsynopsisdiv-title">Synopsis</h2>
<div class="refsynopsisdiv"><pre class="synopsis"><span class="comment">// In header: &lt;<a class="link" href="../../interprocess/indexes_reference.html#header.boost.interprocess.mem_algo.rbtree_best_fit_hpp" title="Header &lt;boost/interprocess/mem_algo/rbtree_best_fit.hpp&gt;">boost/interprocess/mem_algo/rbtree_best_fit.hpp</a>&gt;

</span><span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> MutexFamily<span class="special">,</span> <span class="keyword">typename</span> VoidPointer<span class="special">,</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> MemAlignment<span class="special">&gt;</span> 
<span class="keyword">class</span> <a class="link" href="rbtree_best_fit.html" title="Class template rbtree_best_fit">rbtree_best_fit</a> <span class="special">{</span>
<span class="keyword">public</span><span class="special">:</span>
  <span class="comment">// types</span>
  <span class="keyword">typedef</span> <span class="identifier">MutexFamily</span>                                                   <a name="boost.interprocess.rbtree_best_fit.mutex_family"></a><span class="identifier">mutex_family</span><span class="special">;</span>           <span class="comment">// Shared mutex family used for the rest of the Interprocess framework. </span>
  <span class="keyword">typedef</span> <span class="identifier">VoidPointer</span>                                                   <a name="boost.interprocess.rbtree_best_fit.void_pointer"></a><span class="identifier">void_pointer</span><span class="special">;</span>           <span class="comment">// Pointer type to be used with the rest of the Interprocess framework. </span>
  <span class="keyword">typedef</span> <span class="emphasis"><em><span class="identifier">unspecified</span></em></span>                                                   <a name="boost.interprocess.rbtree_best_fit.multiallocation_chain"></a><span class="identifier">multiallocation_chain</span><span class="special">;</span>
  <span class="keyword">typedef</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">intrusive</span><span class="special">::</span><span class="identifier">pointer_traits</span><span class="special">&lt;</span> <span class="identifier">char_ptr</span> <span class="special">&gt;</span><span class="special">::</span><span class="identifier">difference_type</span> <a name="boost.interprocess.rbtree_best_fit.difference_type"></a><span class="identifier">difference_type</span><span class="special">;</span>      
  <span class="keyword">typedef</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">container</span><span class="special">::</span><span class="identifier">dtl</span><span class="special">::</span><span class="identifier">make_unsigned</span><span class="special">&lt;</span> <span class="identifier">difference_type</span> <span class="special">&gt;</span><span class="special">::</span><span class="identifier">type</span> <a name="boost.interprocess.rbtree_best_fit.size_type"></a><span class="identifier">size_type</span><span class="special">;</span>            

  <span class="comment">// <a class="link" href="rbtree_best_fit.html#boost.interprocess.rbtree_best_fitconstruct-copy-destruct">construct/copy/destruct</a></span>
  <a class="link" href="../container/basic_string.html#idm27884-bb"><span class="identifier">rbtree_best_fit</span></a><span class="special">(</span><span class="identifier">size_type</span><span class="special">,</span> <span class="identifier">size_type</span><span class="special">)</span><span class="special">;</span>
  <a class="link" href="rbtree_best_fit.html#idm27891-bb"><span class="special">~</span><span class="identifier">rbtree_best_fit</span></a><span class="special">(</span><span class="special">)</span><span class="special">;</span>

  <span class="comment">// <a class="link" href="rbtree_best_fit.html#idm27809-bb">public member functions</a></span>
  <span class="keyword">void</span> <span class="special">*</span> <a class="link" href="rbtree_best_fit.html#idm27810-bb"><span class="identifier">allocate</span></a><span class="special">(</span><span class="identifier">size_type</span><span class="special">)</span><span class="special">;</span>
  <span class="keyword">void</span> <a class="link" href="rbtree_best_fit.html#idm27815-bb"><span class="identifier">deallocate</span></a><span class="special">(</span><span class="keyword">void</span> <span class="special">*</span><span class="special">)</span><span class="special">;</span>
  <span class="identifier">size_type</span> <a class="link" href="rbtree_best_fit.html#idm27820-bb"><span class="identifier">get_size</span></a><span class="special">(</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span>
  <span class="identifier">size_type</span> <a class="link" href="rbtree_best_fit.html#idm27823-bb"><span class="identifier">get_free_memory</span></a><span class="special">(</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span>
  <span class="keyword">void</span> <a class="link" href="../container/basic_string.html#idm27826-bb"><span class="identifier">zero_free_memory</span></a><span class="special">(</span><span class="special">)</span><span class="special">;</span>
  <span class="keyword">void</span> <a class="link" href="rbtree_best_fit.html#idm27830-bb"><span class="identifier">grow</span></a><span class="special">(</span><span class="identifier">size_type</span><span class="special">)</span><span class="special">;</span>
  <span class="keyword">void</span> <a class="link" href="rbtree_best_fit.html#idm27836-bb"><span class="identifier">shrink_to_fit</span></a><span class="special">(</span><span class="special">)</span><span class="special">;</span>
  <span class="keyword">bool</span> <a class="link" href="rbtree_best_fit.html#idm27839-bb"><span class="identifier">all_memory_deallocated</span></a><span class="special">(</span><span class="special">)</span><span class="special">;</span>
  <span class="keyword">bool</span> <a class="link" href="rbtree_best_fit.html#idm27842-bb"><span class="identifier">check_sanity</span></a><span class="special">(</span><span class="special">)</span><span class="special">;</span>
  <span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> T<span class="special">&gt;</span> 
    <span class="identifier">T</span> <span class="special">*</span> <a class="link" href="../container/basic_string.html#idm27846-bb"><span class="identifier">allocation_command</span></a><span class="special">(</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">interprocess</span><span class="special">::</span><span class="identifier">allocation_type</span><span class="special">,</span> <span class="identifier">size_type</span><span class="special">,</span> 
                           <span class="identifier">size_type</span> <span class="special">&amp;</span><span class="special">,</span> <span class="identifier">T</span> <span class="special">*</span><span class="special">&amp;</span><span class="special">)</span><span class="special">;</span>
  <span class="keyword">void</span> <span class="special">*</span> <a class="link" href="rbtree_best_fit.html#idm27858-bb"><span class="identifier">raw_allocation_command</span></a><span class="special">(</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">interprocess</span><span class="special">::</span><span class="identifier">allocation_type</span><span class="special">,</span> 
                                <span class="identifier">size_type</span><span class="special">,</span> <span class="identifier">size_type</span> <span class="special">&amp;</span><span class="special">,</span> <span class="keyword">void</span> <span class="special">*</span><span class="special">&amp;</span><span class="special">,</span> 
                                <span class="identifier">size_type</span> <span class="special">=</span> <span class="number">1</span><span class="special">)</span><span class="special">;</span>
  <span class="identifier">size_type</span> <a class="link" href="rbtree_best_fit.html#idm27871-bb"><span class="identifier">size</span></a><span class="special">(</span><span class="keyword">const</span> <span class="keyword">void</span> <span class="special">*</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span>
  <span class="keyword">void</span> <span class="special">*</span> <a class="link" href="rbtree_best_fit.html#idm27876-bb"><span class="identifier">allocate_aligned</span></a><span class="special">(</span><span class="identifier">size_type</span><span class="special">,</span> <span class="identifier">size_type</span><span class="special">)</span><span class="special">;</span>

  <span class="comment">// <a class="link" href="../container/basic_string.html#idm27893-bb">public static functions</a></span>
  <span class="keyword">static</span> <span class="identifier">size_type</span> <a class="link" href="rbtree_best_fit.html#idm27894-bb"><span class="identifier">get_min_size</span></a><span class="special">(</span><span class="identifier">size_type</span><span class="special">)</span><span class="special">;</span>

  <span class="comment">// public data members</span>
  <span class="keyword">static</span> <span class="keyword">const</span> <span class="identifier">size_type</span> <span class="identifier">PayloadPerAllocation</span><span class="special">;</span>
<span class="special">}</span><span class="special">;</span></pre></div>
<div class="refsect1">
<a name="id-1.3.17.17.3.41.4.4"></a><h2>Description</h2>
<p>This class implements an algorithm that stores the free nodes in a red-black tree to have logarithmic search/insert times. </p>
<div class="refsect2">
<a name="id-1.3.17.17.3.41.4.4.3"></a><h3>
<a name="boost.interprocess.rbtree_best_fitconstruct-copy-destruct"></a><code class="computeroutput">rbtree_best_fit</code> 
        public
       construct/copy/destruct</h3>
<div class="orderedlist"><ol class="orderedlist" type="1">
<li class="listitem">
<pre class="literallayout"><a name="idm27884-bb"></a><span class="identifier">rbtree_best_fit</span><span class="special">(</span><span class="identifier">size_type</span> size<span class="special">,</span> <span class="identifier">size_type</span> extra_hdr_bytes<span class="special">)</span><span class="special">;</span></pre>
<p>Constructor. "size" is the total size of the managed memory segment, "extra_hdr_bytes" indicates the extra bytes beginning in the sizeof(rbtree_best_fit) offset that the allocator should not use at all. </p>
</li>
<li class="listitem">
<pre class="literallayout"><a name="idm27891-bb"></a><span class="special">~</span><span class="identifier">rbtree_best_fit</span><span class="special">(</span><span class="special">)</span><span class="special">;</span></pre>Destructor. </li>
</ol></div>
</div>
<div class="refsect2">
<a name="id-1.3.17.17.3.41.4.4.4"></a><h3>
<a name="idm27809-bb"></a><code class="computeroutput">rbtree_best_fit</code> public member functions</h3>
<div class="orderedlist"><ol class="orderedlist" type="1">
<li class="listitem">
<pre class="literallayout"><span class="keyword">void</span> <span class="special">*</span> <a name="idm27810-bb"></a><span class="identifier">allocate</span><span class="special">(</span><span class="identifier">size_type</span> nbytes<span class="special">)</span><span class="special">;</span></pre>Allocates bytes, returns 0 if there is not more memory. </li>
<li class="listitem">
<pre class="literallayout"><span class="keyword">void</span> <a name="idm27815-bb"></a><span class="identifier">deallocate</span><span class="special">(</span><span class="keyword">void</span> <span class="special">*</span> addr<span class="special">)</span><span class="special">;</span></pre>Deallocates previously allocated bytes. </li>
<li class="listitem">
<pre class="literallayout"><span class="identifier">size_type</span> <a name="idm27820-bb"></a><span class="identifier">get_size</span><span class="special">(</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span></pre>Returns the size of the memory segment. </li>
<li class="listitem">
<pre class="literallayout"><span class="identifier">size_type</span> <a name="idm27823-bb"></a><span class="identifier">get_free_memory</span><span class="special">(</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span></pre>Returns the number of free bytes of the segment. </li>
<li class="listitem">
<pre class="literallayout"><span class="keyword">void</span> <a name="idm27826-bb"></a><span class="identifier">zero_free_memory</span><span class="special">(</span><span class="special">)</span><span class="special">;</span></pre>
<p>Initializes to zero all the memory that's not in use. This function is normally used for security reasons. </p>
</li>
<li class="listitem">
<pre class="literallayout"><span class="keyword">void</span> <a name="idm27830-bb"></a><span class="identifier">grow</span><span class="special">(</span><span class="identifier">size_type</span> extra_size<span class="special">)</span><span class="special">;</span></pre>
<p>Increases managed memory in extra_size bytes more </p>
</li>
<li class="listitem">
<pre class="literallayout"><span class="keyword">void</span> <a name="idm27836-bb"></a><span class="identifier">shrink_to_fit</span><span class="special">(</span><span class="special">)</span><span class="special">;</span></pre>Decreases managed memory as much as possible. </li>
<li class="listitem">
<pre class="literallayout"><span class="keyword">bool</span> <a name="idm27839-bb"></a><span class="identifier">all_memory_deallocated</span><span class="special">(</span><span class="special">)</span><span class="special">;</span></pre>Returns true if all allocated memory has been deallocated. </li>
<li class="listitem">
<pre class="literallayout"><span class="keyword">bool</span> <a name="idm27842-bb"></a><span class="identifier">check_sanity</span><span class="special">(</span><span class="special">)</span><span class="special">;</span></pre>
<p>Makes an internal sanity check and returns true if success </p>
</li>
<li class="listitem"><pre class="literallayout"><span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> T<span class="special">&gt;</span> 
  <span class="identifier">T</span> <span class="special">*</span> <a name="idm27846-bb"></a><span class="identifier">allocation_command</span><span class="special">(</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">interprocess</span><span class="special">::</span><span class="identifier">allocation_type</span> command<span class="special">,</span> 
                         <span class="identifier">size_type</span> limit_size<span class="special">,</span> 
                         <span class="identifier">size_type</span> <span class="special">&amp;</span> prefer_in_recvd_out_size<span class="special">,</span> <span class="identifier">T</span> <span class="special">*</span><span class="special">&amp;</span> reuse<span class="special">)</span><span class="special">;</span></pre></li>
<li class="listitem"><pre class="literallayout"><span class="keyword">void</span> <span class="special">*</span> <a name="idm27858-bb"></a><span class="identifier">raw_allocation_command</span><span class="special">(</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">interprocess</span><span class="special">::</span><span class="identifier">allocation_type</span> command<span class="special">,</span> 
                              <span class="identifier">size_type</span> limit_object<span class="special">,</span> 
                              <span class="identifier">size_type</span> <span class="special">&amp;</span> prefer_in_recvd_out_size<span class="special">,</span> 
                              <span class="keyword">void</span> <span class="special">*</span><span class="special">&amp;</span> reuse_ptr<span class="special">,</span> <span class="identifier">size_type</span> sizeof_object <span class="special">=</span> <span class="number">1</span><span class="special">)</span><span class="special">;</span></pre></li>
<li class="listitem">
<pre class="literallayout"><span class="identifier">size_type</span> <a name="idm27871-bb"></a><span class="identifier">size</span><span class="special">(</span><span class="keyword">const</span> <span class="keyword">void</span> <span class="special">*</span> ptr<span class="special">)</span> <span class="keyword">const</span><span class="special">;</span></pre>Returns the size of the buffer previously allocated pointed by ptr. </li>
<li class="listitem">
<pre class="literallayout"><span class="keyword">void</span> <span class="special">*</span> <a name="idm27876-bb"></a><span class="identifier">allocate_aligned</span><span class="special">(</span><span class="identifier">size_type</span> nbytes<span class="special">,</span> <span class="identifier">size_type</span> alignment<span class="special">)</span><span class="special">;</span></pre>
<p>Allocates aligned bytes, returns 0 if there is not more memory. Alignment must be power of 2 </p>
</li>
</ol></div>
</div>
<div class="refsect2">
<a name="id-1.3.17.17.3.41.4.4.5"></a><h3>
<a name="idm27893-bb"></a><code class="computeroutput">rbtree_best_fit</code> public static functions</h3>
<div class="orderedlist"><ol class="orderedlist" type="1"><li class="listitem">
<pre class="literallayout"><span class="keyword">static</span> <span class="identifier">size_type</span> <a name="idm27894-bb"></a><span class="identifier">get_min_size</span><span class="special">(</span><span class="identifier">size_type</span> extra_hdr_bytes<span class="special">)</span><span class="special">;</span></pre>Obtains the minimum size needed by the algorithm. </li></ol></div>
</div>
</div>
</div>
<div class="copyright-footer">Copyright © 2005-2015 Ion Gaztanaga<p>
        Distributed under the Boost Software License, Version 1.0. (See accompanying
        file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
      </p>
</div>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="mapped_region/advice_types.html"><img src="../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../../interprocess/indexes_reference.html#header.boost.interprocess.mem_algo.rbtree_best_fit_hpp"><img src="../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="simple_seq_fit.html"><img src="../../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>
